package de.so.myteach;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import de.so.myteach.dummy.DummyContent;
import de.so.myteach.dummy.DummyContent.DummyItem;

public class PupilDetailFragment extends Fragment
{
  public static final String ARG_ITEM_ID = "item_id";
  private static boolean twoPane;
  private DummyItem mItem;
  private MyAdapter Adapter;

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    if (getArguments().containsKey("item_id"))
      this.mItem = ((DummyItem)DummyContent.ITEM_MAP.get(getArguments().getString("item_id")));
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView = paramLayoutInflater.inflate(R.layout.fragment_pupil_detail, paramViewGroup, false);
    twoPane = Boolean.parseBoolean(paramLayoutInflater.getContext().getResources().getString(R.string.twoPane));
    if (this.mItem != null)
    {
      Adapter = new MyAdapter(getChildFragmentManager(),twoPane);
      ((ViewPager)localView.findViewById(R.id.pupil_detail_viewpager)).setAdapter(Adapter);
    }
    return localView;
  }

  public static class MyAdapter extends FragmentPagerAdapter
  {
    private boolean twoPane=false;
    public MyAdapter(FragmentManager paramFragmentManager,boolean twoPane)
    {
      super(paramFragmentManager);
      this.twoPane=twoPane;
    }

    public int getCount()
    {
      if (this.twoPane) {
          return 2;
      }
      return 4;
    }

    public Fragment getItem(int paramInt)
    {
      if (this.twoPane) {
        switch (paramInt)
        {
            case 0:
                return new PupilDetailMainInfoContactInfoFragment();
            case 1:
                return new PupilDetailGradeInfoMissInfoFragment();
            default:
                return null;
        }
      }
      else {
         switch (paramInt)
         {
          case 0:
              return new PupilDetailMainInfoFragment();
          case 1:
              return new PupilDetailContactInfoFragment();
          case 2:
              return new PupilDetailGradeInfoFragment();
          case 3:
        	  return new PupilDetailMissInfoFragment();
          default:
              return null;
         }
      }
    }
  }
}